package login;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

//自定义类，放在mapper输出的key上，要求实现序列化，实现可比较WritableComparable
public class MemberDate implements WritableComparable<MemberDate> {

    String username;
    String date;

    public MemberDate() {
    }

    public MemberDate(String username, String date) {
        this.username = username;
        this.date = date;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    @Override //比较 当前对象如果小于o,返回复数，当前对象等于o，返回0，当前对象大于o，返回正数
    //默认实现升序排列，当前类型的值比0小，返回-1，一样大返回0，比0大返回1
    public int compareTo(MemberDate o) {
        int res = this.username.compareTo(o.username);
        if (res != 0)
        {
            return res;
        }
        else
        {
            int res2 = this.date.compareTo(o.date);
            return res2;
        }
    }

    @Override //序列化
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(this.username);
        dataOutput.writeUTF(this.date);

    }

    @Override //反序列化
    public void readFields(DataInput dataInput) throws IOException {
        this.username = dataInput.readUTF();
        this.date = dataInput.readUTF();

    }

    @Override
    public String toString() {
        return "用户名：" +this.username+"登陆日期："+this.date;

    }
}
